<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>4649：Sum</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">Sum</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">Sum</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                Sum                </h1>
                <p>时间限制：50s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：512MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><div>给一棵大小为(n&lt;=100000)的树，每个点有权值vi。要求支持以下操作：</div>
<div>子树加、子树对某数取max/min、链加、链对某数取max/min、子树修改、链修改、链权值翻转、子树求和、链求和。输出对10^9+7取模的非负结果即可。</div>
<div>树有根为1。保证输入中的链权值翻转操作的i为j的祖先。</div>
<div></div>
<p></p></p><hr/><h3>输入格式</h3><p><div>输入第一行一个正整数n，第二行n个整数v，第三行到第n+1行每行两个数u、v代表u和v之间有一条边。</div>
<div>接下来一行一个整数(m&lt;=100000)，下面m行每行一个操作。操作格式如下：</div>
<div>SUBADD i v i的子树加上v</div>
<div>SUBMAX i v i的子树对v取max</div>
<div>SUBMIN i v i的子树对v取min</div>
<div>CHAINADD i j v i到j的路径上每个点加上v</div>
<div>CHAINMAX i j v i到j的路径上每个点对v取max</div>
<div>CHAINMIN i j v i到j的路径上每个点对v取min</div>
<div>SUBXGW i v i的子树修改为v</div>
<div>CHAINXGW i j v i到j的路径上每个点修改为v</div>
<div>CHAINREV i j i到j的路径进行权值翻转</div>
<div>SUBQUE i 输出i的子树和</div>
<div>CHAINQUE i j 输出i到j路径上的权值和</div>
<div>操作中所有v和点的初始权值v满足v&lt;=1000000，保证全程不会有点权值超过10^9+7</div>
<p></p></p><hr/><h3>输出格式</h3><p><p>对于每个求和操作输出一行代表对应权值和。</p>
<p></p></p><hr/><h3>样例输入</h3><pre>10
-3 -2 1 3 1 -2 0 -5 1 4 
2 1
3 1
4 1
5 2
6 4
7 3
8 2
9 3
10 2
19
SUBADD 4 2
SUBXGW 9 -5
CHAINQUE 1 1
SUBQUE 9
SUBMAX 7 -1
SUBMIN 10 2
CHAINQUE 6 9
SUBQUE 1
CHAINADD 9 3 4
CHAINXGW 5 7 5
CHAINQUE 7 7
SUBQUE 1
CHAINMAX 8 7 -5
CHAINMIN 5 3 4
CHAINQUE 3 1
SUBQUE 5
CHAINREV 1 7
CHAINQUE 3 2
SUBQUE 7</pre><hr/><h3>样例输出</h3><pre>1000000004
1000000002
1000000005
1000000001
5
26
8
4
13
4</pre><hr/><h3>提示</h3><p>没有写明提示</p><hr/><h3>题目来源</h3><p>By DpDarkFantasy</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=4649" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=4649" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>